<?php

use Illuminate\Database\Seeder;

class GoodsSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // Type - 优惠类型，数组越大，权重越高
        // 0 - 无优惠
        // 1 - 95折优惠
        // 2 - 买二赠一
        $discount_type = [0,1,2];
        $goods_unit = ['瓶','斤','个','盒','袋','条','桶'];
        for ($i = 0; $i < 10; $i++) {
            $data = [
                        'barcode'   => 'ITEM00' . sprintf("%02d",$i),
                        'name'   => '商品' . sprintf("%02d",$i),
                        'unit'   => $goods_unit[mt_rand(0,6)],
                        'price'    => sprintf("%.2f",mt_rand(3,30)),
                        'discount_type' => array_rand($discount_type, mt_rand(1,3))
                    ];
            $data['discount_type'] = serialize(is_array($data['discount_type']) ? $data['discount_type'] : [$data['discount_type']]);
            \App\Goods::create($data);
        }
    }
}